<template>
  <div @click="handle">
    <div>
      <transition name="el-fade-in-linear">
        <router-view />
      </transition>
      <div>
        <Tool />
      </div>
    </div>
  </div>
</template>

<script>

import Cookies from 'js-cookie'
// import { messages } from '@/i18n'
import Tool from './views/modules/tool/tool.vue'

export default {
  components: {
    Tool
  },

  watch: {
    '$i18n.locale': 'i18nHandle',
    loadingStatus (val) {
      if (val) { this.openLoading() } else { window.SITE_CONFIG['pageLoading'] && window.SITE_CONFIG['pageLoading'].close() }
    }
  },
  created () {
    this.i18nHandle(this.$i18n.locale)
  },
  computed: {
    loadingStatus () {
      return this.$store.state.app.apiLoadStatus
    }
  },

  methods: {
    handle () {
      this.$store.commit('SET_VISBLE_STATUS', false)
    },
    i18nHandle (val, oldVal) {
      window.location.protocol === 'https:'? Cookies.set('language', val, { sameSite: 'None', secure: true }) :  Cookies.set('language', val)
      document.querySelector('html').setAttribute('lang', val)
      // document.title = messages[val].brand.lg
      if (this.$route.name !== 'login' && oldVal) {
        window.location.reload()
      }
    },
    openLoading () {
      const loading = this.$loading({
        lock: true,
        text: this.$store.state.app.apiLoadText,
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      window.SITE_CONFIG['pageLoading'] = loading
    }
  }
}
</script>
